﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LocalCharge.Edit.aspx.cs"
    Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <!--#include virtual="include/Head.ascx"-->

    <script type='text/javascript' src="assets/js/Carrs.js"></script>

    <script type='text/javascript' src="assets/js/Ports.js"></script>

    <script type="text/javascript">
        function getUrlVars() {
            var vars = {};
            var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
                vars[key] = value;
            });
            return vars;
        }
        $().ready(function () {
            $('#txtCarr').focus().autocomplete(carrs, { matchContains: true });
            $('#txtPort').focus().autocomplete(ports, { matchContains: true });
            //Vat 5%
            $( ".BuyPrice" ).blur(function() {
                var obj=$(this).parent().parent();
                var lcId=$(obj).attr("lcID");                
                var fbuyprice=$(this).val(); 
                var fsellpricewithvat=fbuyprice*1.05;                                
                var fsellpricenovat=fsellpricewithvat/1.1;
                var objNoVaT=$(obj).children().find('.SellPriceNoVat');                                             
                var objWithVaT=$(obj).children().find('.SellPriceWithVat');                                             
                $(objNoVaT).val(fsellpricenovat.toFixed(2));
                $(objWithVaT).val(fsellpricewithvat.toFixed(2));                
              });
              //VAT 0%
//               $( ".SellPriceNoVat" ).blur(function() {
//                var obj=$(this).parent().parent();
//                var lcId=$(obj).attr("lcID");
//                var fsellpricenovat=$(this).val();
//                var fbuyprice=fsellpricenovat*1.05;
//                var fsellpricewithvat=fsellpricenovat*1.1;                                
//                var objBuyPrice=$(obj).children().find('.BuyPrice');                                             
//                var objWithVaT=$(obj).children().find('.SellPriceWithVat');                                             
//                $(objBuyPrice).val(fbuyprice.toFixed(2));
//                $(objWithVaT).val(fsellpricewithvat.toFixed(2));                
//              });
              //VAT 10 %
               $( ".SellPriceWithVat" ).blur(function() {
                var obj=$(this).parent().parent();
                var lcId=$(obj).attr("lcID");
                var fsellpricewithvat=$(this).val();
                var fsellpricenovat=fsellpricewithvat/1.1;
                var fbuyprice=fsellpricewithvat/1.05;                                
                var objBuyPrice=$(obj).children().find('.BuyPrice');                                             
                var objNoVaT=$(obj).children().find('.SellPriceNoVat');                                             
                $(objNoVaT).val(fsellpricenovat.toFixed(2));
                $(objBuyPrice).val(fbuyprice.toFixed(2)); 
              });
               var sumBuyPriceUSD=0;
                var sumSellNoVatUSD=0;
                var sumSellWithVatUSD=0;
                var sumBuyPriceVND=0;
                var sumSellNoVatVND=0;
                var sumSellWithVatVND=0;
             $(":checkbox").change(function() {
                var obj=$(this).parent().parent();
                    var fbuyprice=$(obj).children().find('.BuyPrice').val();
                    var fsellnovat=$(obj).children().find('.SellPriceNoVat').val();                                             
                    var fsellwithvat=$(obj).children().find('.SellPriceWithVat').val(); 
                    var currencyType=$(obj).children().find('.ddCurrencyType').val();
                    //alert("fbuyprice="+fbuyprice+", fsellnovat="+fsellnovat+", fsellwithvat="+fsellwithvat+", type="+currencyType);        
                if(this.checked) {
                    //Cong tong
                    if(currencyType==2)
                    {
                   
                        sumBuyPriceVND+= parseFloat(fbuyprice.replace(/,/g,""));
                        sumSellNoVatVND+=parseFloat(fsellnovat.replace(/,/g,""));
                        sumSellWithVatVND+=parseFloat(fsellwithvat.replace(/,/g,""));   
                    }
                    else
                    {
                        sumBuyPriceUSD+=parseFloat(fbuyprice.replace(/,/g,""));
                        sumSellNoVatUSD+=parseFloat(fsellnovat.replace(/,/g,""));
                        sumSellWithVatUSD+=parseFloat(fsellwithvat.replace(/,/g,""));    
                    }
                }
                else
                {
                     if(currencyType==2)
                    {
                        sumBuyPriceVND-=parseFloat(fbuyprice.replace(/,/g,""));
                        sumSellNoVatVND-=parseFloat(fsellnovat.replace(/,/g,""));
                        sumSellWithVatVND-=parseFloat(fsellwithvat.replace(/,/g,""));
                    }
                    else
                    {
                        sumBuyPriceUSD-=parseFloat(fbuyprice.replace(/,/g,""));
                        sumSellNoVatUSD-=parseFloat(fsellnovat.replace(/,/g,""));
                        sumSellWithVatUSD-=parseFloat(fsellwithvat.replace(/,/g,""));  
                    }    
                }
                //Display Sum
                $("#buyPrice_USD").text(formatNumber(sumBuyPriceUSD));
                $("#sellNoVAT_USD").text(formatNumber(sumSellNoVatUSD));
                $("#sellWithVAT_USD").text(formatNumber(sumSellWithVatUSD));
                $("#buyPrice_VND").text(formatNumber(sumBuyPriceVND));
                $("#sellNoVAT_VND").text(formatNumber(sumSellNoVatVND));
                $("#sellWithVAT_VND").text(formatNumber(sumSellWithVatVND));
            });
        });
        
        function doBack() {
          
                var vnpage = getUrlVars()['page_number'];
                var strHref = "";
                if (vnpage)
                    strHref = "LocalCharge.aspx?page_number=" + vnpage;
                else
                    strHref =  "LocalCharge.aspx";
                window.location.href = strHref;          
        }
       
    </script>

    <style type="text/css">
        .thheader
        {
            font-weight: bold;
            vertical-align: middle;
            text-align: center;
            font-size: 11px;
            border: 1px solid #ccc !important;
            line-height: 7px !important; ;}
        .adminedit tbody tr td
        {
            border: 1px solid;
        }
        .bottom td
        {
            font-weight: bold;
            text-align: left;
        }
    </style>
</head>
<body>
    <div id="body-wrapper">
        <div id="header">
            <!--#include virtual="include/top.ascx"-->
        </div>
        <div id="main-content1">
            <h2>
                Chi tiết chi phí địa phương</h2>
            <div class="clear">
            </div>
            <div>
                <asp:Label ID="lblError" CssClass="error" Text="" runat="server"></asp:Label></div>
            <div class="content-box" style="width: 80%">
                <form id="frmLocalCosts" runat="server">
                <div class="content-box-header">
                    <h3 style="cursor: s-resize;">
                        <%if(Request.QueryString["ID"]!=null){ %>
                        Carrier:
                        <asp:Label ID="lblCarrier" runat="server"></asp:Label>
                        &nbsp;&nbsp; Update:
                        <asp:Label ID="lblLocalChargeUpdate" runat="server"></asp:Label>
                        <%} %>
                    </h3>
                    <input id="Button1" type="button" style="float: right; margin: 5px 10px;" class="button"
                        value="&nbsp;&nbsp;Back&nbsp;&nbsp;" onclick="doBack();" />
                    <asp:Button class="button" ID="btnSave" Style="float: right; margin: 5px; width: 70px;
                        font-weight: bold;" runat="server" Text="Save" OnClick="btnSave_Click" />
                    <div class="clear">
                    </div>
                </div>
                <fieldset>
                    <div style="margin: 10px; font-weight: bold;">
                        CARR:
                        <asp:TextBox class="cls" ID="txtCarr" runat="server" Width="100px"></asp:TextBox>
                        PORT:
                        <asp:TextBox class="cls" ID="txtPort" runat="server" Width="100px"></asp:TextBox>
                        &nbsp; &nbsp; &nbsp; NOTE:
                        <asp:TextBox ID="txtLocalChargeNote" runat="server" Width="501px"></asp:TextBox>
                    </div>
                    <asp:Repeater ID="rptData" runat="server" OnItemDataBound="rptData_ItemDataBound">
                        <ItemTemplate>
                            <tr onmouseover="this.style.background='#dbf0c9'" onmouseout="this.style.background='#ffffff'"
                                lcindex='<%#Eval("Index") %>' lcid='<%#Eval("ID") %>'>
                                <td>
                                    <%# DataBinder.Eval(Container.DataItem, "MajorCode")%>
                                    <asp:HiddenField ID="MajorCode" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "MajorCode")%>'>
                                    </asp:HiddenField>
                                    <asp:HiddenField ID="ID" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "ID")%>'>
                                    </asp:HiddenField>
                                    <asp:HiddenField ID="Index" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "Index")%>'>
                                    </asp:HiddenField>
                                </td>
                                <td>
                                    <%# DataBinder.Eval(Container.DataItem, "InnerCode")%>
                                    <asp:HiddenField ID="InnerCode" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "InnerCode")%>'>
                                    </asp:HiddenField>
                                    <asp:HiddenField ID="Code" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "Code")%>'>
                                    </asp:HiddenField>
                                </td>
                                <td>
                                    <%#DataBinder.Eval(Container.DataItem, "Unit")%>
                                    <asp:HiddenField ID="Unit" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "Unit")%>'>
                                    </asp:HiddenField>
                                </td>
                                <td>
                                    <input type="CheckBox" value='<%#Eval("Index") %>' id="cbSelect" name="cbSelect"
                                        style='<%#Eval("Code").ToString()=="LPF_DAYS"? "display:none": "" %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="CurrencyType" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CurrencyType")%>'
                                        Style="display: none;" CssClass="TypeOfCurrency"></asp:TextBox>
                                    <asp:DropDownList ID="ddCurrencyType" runat="server" CssClass="ddCurrencyType" Visible='<%#Eval("Code").ToString()!="LPF_DAYS"? true:false %>'>
                                        <asp:ListItem Text="USD" Value="1"></asp:ListItem>
                                        <asp:ListItem Text="VND" Value="2"></asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                                <td>
                                    <asp:TextBox ID="BuyPrice" runat="server" class='<%#Eval("Code").ToString()!="LPF_DAYS"?"BuyPrice":"" %>'
                                        Text='<%# DataBinder.Eval(Container.DataItem, "BuyPrice")%>'></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="SellPriceNoVat" runat="server" class='<%#Eval("Code").ToString()!="LPF_DAYS"?"SellPriceNoVat":"" %>'
                                        Text='<%# DataBinder.Eval(Container.DataItem, "SellPriceNoVat")%>'></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="SellPriceWithVat" runat="server" class='<%#Eval("Code").ToString()!="LPF_DAYS"?"SellPriceWithVat":"" %>'
                                        Text='<%# DataBinder.Eval(Container.DataItem, "SellPriceWithVat")%>'></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="Note" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Note")%>'></asp:TextBox>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <HeaderTemplate>
                            <table cellspacing="0" cellpadding="0" width="100%" border="0" class="adminlist">
                                <thead>
                                    <tr>
                                        <th align="center" colspan="2">
                                            Chi tiết
                                        </th>
                                        <th align="center" rowspan="3">
                                            ĐVT
                                        </th>
                                        <th align="center">
                                            Chọn
                                        </th>
                                        <th align="center">
                                            Loại tiền
                                        </th>
                                        <th align="center">
                                            Mua vào (VAT 5%)
                                        </th>
                                        <th align="center">
                                            Bán ra chưa VAT
                                        </th>
                                        <th align="center">
                                            Bán ra có VAT (10%)
                                        </th>
                                        <th align="center">
                                            Ghi chú
                                        </th>
                                    </tr>
                                </thead>
                        </HeaderTemplate>
                        <FooterTemplate>
                            <tr class="bottom">
                                <td colspan="4" rowspan="2">
                                    Tổng cộng
                                </td>
                                <td>
                                    USD
                                </td>
                                <td id="buyPrice_USD">
                                </td>
                                <td id="sellNoVAT_USD">
                                </td>
                                <td id="sellWithVAT_USD">
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr class="bottom">
                                <td>
                                    VND
                                </td>
                                <td id="buyPrice_VND">
                                </td>
                                <td id="sellNoVAT_VND">
                                </td>
                                <td id="sellWithVAT_VND">
                                </td>
                                <td>
                                </td>
                            </tr>
                            </TABLE>
                        </FooterTemplate>
                    </asp:Repeater>
                </fieldset>
                <div class="clear">
                </div>
                <div id="footer">
                </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
